package com.example.service;

import com.example.exception.DeleteFileFailedException;
import com.example.util.RabbitMQUtil;

/**
 * @author Lexin Huang
 */
public interface AvatarService extends ServerUploadFileService {

    /**
     * 判断是否需要删除头像
     *
     * @param avatarUrl 头像资源 url
     * @return 头像是否需要删除
     */
    boolean needToRemove(String avatarUrl);

    /**
     * 删除用户上传的头像 (如果头像存在且不是默认头像)
     *
     * @param avatarUrl 超链接形式的头像路径
     * @throws DeleteFileFailedException 当图片存在且删除失败时
     */
    default void removeAvatarIfNotDefault(String avatarUrl) {
        if (needToRemove(avatarUrl)) {
            boolean deleteSuccess = deleteFileByUrl(avatarUrl);
            if (!deleteSuccess) {
                throw new DeleteFileFailedException("删除URL:" + avatarUrl + "的图片失败!");
            }
        }
    }



}
